<?php
/**
 * Created by PhpStorm.
 * User: jianglong
 * Date: 2017/11/7
 * Time: 下午3:33
 */

namespace app\common\log\createAccount;
use app\user\validate\User;
/**
 * 创建客户经理账号,领导账号
 * Class CreateManager
 * @package app\common\log\createAccount
 */
class CreateManager
{
    static public function addOne(array $a_data){
        $a_data = [
            'username' => $a_data['username'], //登录用户名
            'nickname' => $a_data['nickname'], //昵称
            'role' => $a_data['role'],//角色 2=>领导,3-为客户经理
            'email' => $a_data['email'],//邮箱
            'password' => '123456',//初始密码身份证号后六位
            'mobile' => $a_data['mobile'],//手机号
            'role_id' => $a_data['role_id'],//角色id
            'status' => $a_data['status'],//账号状态
        ];
        $o_validate = new User();
        //验证数据的正确性
        if (TRUE !== $o_validate->check($a_data)):
            return $o_validate->getError();
        endif;
        $o_model = new \app\user\model\User();
        if (!$o_model->save($a_data)):
            return '添加失败';
        endif;
        action_log("user_add", "admin_user", $o_model->getLastInsID(), UID);

        return TRUE;
    }
}